<?php

namespace App\Http\Controllers\Admin;

use App\Http\Query\CategoryQuery;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;
use Log;
use SplFileObject;

class CategoryTreeController extends Controller
{

    /**
     * @param Request $request
     *
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function tree(Request $request)
    {
        $list = DB::table('category_master')
            ->orderBy("bpath")
            ->select(DB::raw("category_id as id,pid,category_name,sort,delete_flg,category_image,concat(path,'-',category_id) as bpath"))
            ->where(['delete_flg'=>0])
            ->get()->map(function ($value) {
                return (array)$value;
            })->toArray();
        if ($list != FALSE) {
            $tree = build_tree($list, 0);
        } else {
            $tree = [];
        }
        $tree = lyx_array_sort($tree,'sort');
        return view('admin.category_tree', array(
            'list' => $tree
        ));
    }


}
